const CryptoJS = require('crypto-js')

f = {
    "body": {
        "loginMethod": "1",
        "name": "12222212111",
        "password": "122211112212"
    },
    "head": {
        "userCode": null,
        "channelCode": "101",
        "transTime": 1699233177462,
        "transToken": "",
        "customerId": null,
        "transSerialNumber": ""
    }
}

privaKey = "4D8cnJXEp48HXc5m"

/**
 * 登录参数逆向解析
 * @returns {*}
 */
function parseLoginParam() {
    return newEncrypt(JSON.stringify(f))

}

function newEncrypt(l) {
    var n = CryptoJS.enc.Utf8.parse(privaKey)
        , t = CryptoJS.enc.Utf8.parse(privaKey)
        , e = CryptoJS.enc.Utf8.parse(l)
        , a = CryptoJS.AES.encrypt(e, n, {
        iv: t,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    return CryptoJS.enc.Base64.stringify(a.ciphertext)
}

console.log(parseLoginParam())



encryctReturns = "lVnY1R8uEa6KEUiim7bjZ11XRwPXD3CvVLRKZ8HAqS2k870bxinjJkavnLSdSBWt8Uic+PoPWpt6Afjm+OP+63ryOVZZsVfxgQX1vYMSAZUOjYVthjjv6794Yc0KxJusGhcu9MPMAEMHwsEpxHTBlhPWQyW8GachDh7oLDKQMPpU5uyJFjrll00tVLWpcBpL1r435umsoxu119pwurkvOXLcHI8GBOT99+W3RM4BIAdiqEOa5KqyxbfBHYqRP/xsBW7hyi8fGMdPx9JBmyvqqsKTUsgb0osC/HeRIKFnY+NYDtZ6a/HFvUN32DkC2NKW"

/**
 * 逆向解析返回数据
 * @param l
 * @returns {*}
 */
function parseLoginReturnData() {
    var n = encryctReturns.replace(/[\r\n]/g, "")
    return JSON.parse(newDecoto(n))
}

function newDecoto(l) {
    var n = CryptoJS.enc.Base64.parse(l)
        , t = CryptoJS.enc.Utf8.parse(privaKey)
        , e = CryptoJS.enc.Utf8.parse(privaKey)
        , a = CryptoJS.lib.CipherParams.create({
        ciphertext: n
    });
    return CryptoJS.AES.decrypt(a, t, {
        iv: e,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    }).toString(CryptoJS.enc.Utf8)
}

console.log(parseLoginReturnData())

